package com.foreknow.demo6;

import java.util.Scanner;

/**
 * 创建一个学生类,该类的属性包含(姓名,学号,成绩),设计一个方法按章成绩从高到低的顺序姓名,学号,成绩
 * 1.发现类  以及类中的属性
 * 2.排序   冒泡排序
 * 3.需要创建三个学生对象并将对象保存到数组当中,然后调用方法来实现排序
 */
public class Student {

    private String name;
    private int number;//学号
    private double achievement;//成绩

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

    public double getAchievement() {
        return achievement;
    }

    public void setAchievement(double achievement) {
        this.achievement = achievement;
    }
     //方法排序
     public Student[] temp (Student[] student){
         int [] arr = new int[3];
         int test =0;
        for(int i = 1; i<arr.length;i++){
            for(int j = 1;j<arr.length-i;j++){
                if (student[j].getAchievement()>student[j].getAchievement()){
                     test = arr[i];
                    arr[i]= arr[i+1];
                    arr[i+1]=test;
                }

            }


        }
//         for(int i= 0;i<arr.length;i++){
//             Student student1
//
//         }
         return  student;
     }

    //定义一个排序方法(有没有返回值类型以及参数)
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Student[] students = new Student[3];

        for (int i= 0;i<3;i++){
            Student student = new Student();
//            student.getAchievement();
            System.out.println("输入姓名");
            String name = input.next();
            System.out.println("输入学号");
            int number = input.nextInt();
            System.out.println("输入成绩");
            double achievement = input.nextDouble();

            student.setName(name);
            student.setNumber(number);
            student.setAchievement(achievement);
            students[i] = student;
        }
       Student student=new Student();
        student.temp(students);

        Student student1 = new Student();
        Student[] resultSourt = student1.temp(students);
        //输出便利结果
        for (int i = 0; i<resultSourt.length;i++){
            Student students1 =resultSourt[i];
            System.out.println(students1.getAchievement()+"  ... "+student1.getName()+"   "+student1.getNumber());
        }
    }
}
